library(readxl)
library(readr)
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.2
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 1.0.0 ✔ stringr 1.4.0
## ✔ ggplot2 3.2.1 ✔ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(dplyr)
library(data.table)
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
##
## between, first, last
## The following object is masked from 'package:purrr':
##
## transpose
library(ggrepel)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
SVAC_data <- read_excel("SVAC_dataset update 2016 June 21.xlsx")
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W1298 / R1298C23: got 'Tibetan'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W1409 / R1409C23: got 'Rwanda; Burundi'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W1410 / R1410C23: got 'Rwanda'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX1421 / R1421C50: got 'teacher'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W1422 / R1422C23: got 'Rwanda'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X1438 / R1438C24: got 'Catholic'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X1491 / R1491C24: got 'Catholic'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX1492 / R1492C50: got 'neighbor'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2389 / R2389C50: got '"twnety-five year old
## Dinka women"'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2514 / R2514C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i
## = sheet, : Expecting numeric in AX2514 / R2514C50: got '“witnesses at
## market”'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2515 / R2515C25: got 'girls'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2521 / R2521C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2522 / R2522C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2523 / R2523C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2524 / R2524C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2525 / R2525C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2526 / R2526C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2527 / R2527C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2528 / R2528C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2529 / R2529C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2601 / R2601C25: got '“young women”'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2683 / R2683C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2683 / R2683C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2683 / R2683C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2683 / R2683C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2684 / R2684C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2684 / R2684C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2684 / R2684C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2684 / R2684C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2685 / R2685C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2685 / R2685C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2685 / R2685C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2685 / R2685C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2686 / R2686C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2686 / R2686C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2686 / R2686C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2686 / R2686C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2687 / R2687C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2687 / R2687C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2687 / R2687C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2687 / R2687C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2688 / R2688C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2688 / R2688C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2688 / R2688C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2688 / R2688C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2689 / R2689C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2689 / R2689C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2689 / R2689C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2689 / R2689C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2690 / R2690C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2690 / R2690C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2690 / R2690C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2690 / R2690C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2691 / R2691C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2691 / R2691C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2691 / R2691C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2691 / R2691C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W2692 / R2692C23: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X2692 / R2692C24: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2692 / R2692C25: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2692 / R2692C50: got '.'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2778 / R2778C25: got 'Secondary school aged'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2779 / R2779C25: got 'Secondary school aged
## children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2802 / R2802C25: got 'School children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2807 / R2807C25: got 'School aged children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX2807 / R2807C50: got 'In front of man there
## to buy nuts'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2808 / R2808C25: got 'School aged children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2809 / R2809C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2810 / R2810C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2811 / R2811C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2812 / R2812C25: got 'Children; young girls'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2813 / R2813C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2814 / R2814C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2815 / R2815C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2816 / R2816C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y2826 / R2826C25: got 'children'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W3060 / R3060C23: got 'foreigners'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W3062 / R3062C23: got 'Congolese (DRC)'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W3063 / R3063C23: got 'Congolese (DRC)'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX3142 / R3142C50: got '“interrogator”'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX3996 / R3996C50: got '“fellow passengers”'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i
## = sheet, : Expecting numeric in AX4153 / R4153C50: got 'Two civilian
## brothers'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X4581 / R4581C24: got 'Islam'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W4936 / R4936C23: got 'Kuwaiti'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W4937 / R4937C23: got 'Kuwaiti'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5101 / R5101C50: got 'group of dinner
## guests'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5131 / R5131C50: got '"Other volunteers"'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5250 / R5250C50: got 'passerby'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5347 / R5347C50: got '"in front of …other
## civilians"'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5350 / R5350C50: got 'In front of the whole
## village'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y5355 / R5355C25: got 'Under 17'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5371 / R5371C50: got 'civilians'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X5701 / R5701C24: got 'Muslim'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X5715 / R5715C24: got 'muslim'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X5717 / R5717C24: got 'Muslim'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in Y5717 / R5717C25: got 'child brearing age'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX5717 / R5717C50: got 'other potential
## victims'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X5723 / R5723C24: got 'mus'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W5779 / R5779C23: got 'non serb; Croatian'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X5997 / R5997C24: got 'muslim'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX6286 / R6286C50: got 'Someone passing by
## (killed for protesting the rape)'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W6350 / R6350C23: got 'Ethiopian'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W6352 / R6352C23: got '“Ethiopian”'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in AX6503 / R6503C50: got 'refugees'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in W6540 / R6540C23: got 'Serb, Roma'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X6646 / R6646C24: got 'Muslim'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i =
## sheet, : Expecting numeric in X6648 / R6648C24: got 'Muslim'
hfi <- read_csv("hfi_cc_2018.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## .default = col_double(),
## ISO_code = col_character(),
## countries = col_character(),
## region = col_character()
## )
## See spec(...) for full column specifications.
country <- read_csv("country.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_character(),
## `Personal Freedom` = col_double(),
## `Economic Freedom` = col_double()
## )
hfi_women <- hfi %>% select(year, X1 = countries, region, contains("women")) %>% filter(year == 2016)
hfiwc <- full_join(hfi_women, country)
## Joining, by = "X1"
str(hfi)
## Classes 'spec_tbl_df', 'tbl_df', 'tbl' and 'data.frame': 1458 obs. of 124 variables:
## $ X1 : num 5 6 7 8 9 10 11 12 13 14 ...
## $ year : num 2016 2016 2016 2016 2016 ...
## $ ISO_code : chr "ALB" "DZA" "AGO" "ARG" ...
## $ countries : chr "Albania" "Algeria" "Angola" "Argentina" ...
## $ region : chr "Eastern Europe" "Middle East & North Africa" "Sub-Saharan Africa" "Latin America & the Caribbean" ...
## $ pf_rol_procedural : num 6.66 NA NA 7.1 NA ...
## $ pf_rol_civil : num 4.55 NA NA 5.79 NA ...
## $ pf_rol_criminal : num 4.67 NA NA 4.34 NA ...
## $ pf_rol : num 5.29 3.82 3.45 5.74 5 ...
## $ pf_ss_homicide : num 8.92 9.46 8.06 7.62 8.81 ...
## $ pf_ss_disappearances_disap : num 10 10 5 10 10 10 10 10 10 10 ...
## $ pf_ss_disappearances_violent : num 10 9.29 10 10 10 ...
## $ pf_ss_disappearances_organized : num 10 5 7.5 7.5 7.5 10 10 7.5 NA 2.5 ...
## $ pf_ss_disappearances_fatalities : num 10 9.93 10 10 9.32 ...
## $ pf_ss_disappearances_injuries : num 10 9.99 10 9.99 9.93 ...
## $ pf_ss_disappearances : num 10 8.84 8.5 9.5 9.35 ...
## $ pf_ss_women_fgm : num 10 10 10 10 10 10 10 10 NA 10 ...
## $ pf_ss_women_missing : num 7.5 7.5 10 10 5 10 10 7.5 NA 7.5 ...
## $ pf_ss_women_inheritance_widows : num 5 0 5 10 10 10 10 5 NA 0 ...
## $ pf_ss_women_inheritance_daughters : num 5 0 5 10 10 10 10 10 NA 0 ...
## $ pf_ss_women_inheritance : num 5 0 5 10 10 10 10 7.5 NA 0 ...
## $ pf_ss_women : num 7.5 5.83 8.33 10 8.33 ...
## $ pf_ss : num 8.81 8.04 8.3 9.04 8.83 ...
## $ pf_movement_domestic : num 5 5 0 10 5 10 10 5 10 10 ...
## $ pf_movement_foreign : num 10 5 5 10 5 10 10 5 10 5 ...
## $ pf_movement_women : num 5 5 10 10 10 10 10 5 NA 5 ...
## $ pf_movement : num 6.67 5 5 10 6.67 ...
## $ pf_religion_estop_establish : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_religion_estop_operate : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_religion_estop : num 10 5 10 7.5 5 10 10 2.5 NA 10 ...
## $ pf_religion_harassment : num 9.57 6.87 8.9 9.04 8.58 ...
## $ pf_religion_restrictions : num 8.01 2.96 7.46 6.85 5.09 ...
## $ pf_religion : num 9.19 4.94 8.79 7.8 6.22 ...
## $ pf_association_association : num 10 5 2.5 7.5 7.5 10 10 2.5 NA 5 ...
## $ pf_association_assembly : num 10 5 2.5 10 7.5 10 10 5 NA 0 ...
## $ pf_association_political_establish: num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_association_political_operate : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_association_political : num 10 5 2.5 5 5 10 10 2.5 NA 0 ...
## $ pf_association_prof_establish : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_association_prof_operate : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_association_prof : num 10 5 5 7.5 5 10 10 2.5 NA 10 ...
## $ pf_association_sport_establish : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_association_sport_operate : num NA NA NA NA NA NA NA NA NA NA ...
## $ pf_association_sport : num 10 5 7.5 7.5 7.5 10 10 2.5 NA 10 ...
## $ pf_association : num 10 5 4 7.5 6.5 10 10 3 NA 5 ...
## $ pf_expression_killed : num 10 10 10 10 10 10 10 10 10 10 ...
## $ pf_expression_jailed : num 10 10 10 10 10 ...
## $ pf_expression_influence : num 5 2.67 2.67 5.67 3.33 ...
## $ pf_expression_control : num 5.25 4 2.5 5.5 4.25 7.75 8 0.25 7.25 0.75 ...
## $ pf_expression_cable : num 10 10 7.5 10 7.5 10 10 10 NA 7.5 ...
## $ pf_expression_newspapers : num 10 7.5 5 10 7.5 10 10 0 NA 7.5 ...
## $ pf_expression_internet : num 10 7.5 7.5 10 7.5 10 10 7.5 NA 2.5 ...
## $ pf_expression : num 8.61 7.38 6.45 8.74 7.15 ...
## $ pf_identity_legal : num 0 NA 10 10 7 7 10 0 NA NA ...
## $ pf_identity_parental_marriage : num 10 0 10 10 10 10 10 10 10 0 ...
## $ pf_identity_parental_divorce : num 10 5 10 10 10 10 10 10 10 0 ...
## $ pf_identity_parental : num 10 2.5 10 10 10 10 10 10 10 0 ...
## $ pf_identity_sex_male : num 10 0 0 10 10 10 10 10 10 10 ...
## $ pf_identity_sex_female : num 10 0 0 10 10 10 10 10 10 10 ...
## $ pf_identity_sex : num 10 0 0 10 10 10 10 10 10 10 ...
## $ pf_identity_divorce : num 5 0 10 10 5 10 10 5 NA 0 ...
## $ pf_identity : num 6.25 0.833 7.5 10 8 ...
## $ pf_score : num 7.6 5.28 6.11 8.1 6.91 ...
## $ pf_rank : num 57 147 117 42 84 11 8 131 64 114 ...
## $ ef_government_consumption : num 8.23 2.15 7.6 5.34 7.26 ...
## $ ef_government_transfers : num 7.51 7.82 8.89 6.05 7.75 ...
## $ ef_government_enterprises : num 8 0 0 6 8 10 10 0 7 10 ...
## $ ef_government_tax_income : num 9 7 10 7 5 5 4 9 10 10 ...
## $ ef_government_tax_payroll : num 7 2 9 1 5 5 3 4 10 10 ...
## $ ef_government_tax : num 8 4.5 9.5 4 5 5 3.5 6.5 10 10 ...
## $ ef_government : num 7.94 3.62 6.5 5.35 7 ...
## $ ef_legal_judicial : num 2.67 4.19 1.84 3.69 3.87 ...
## $ ef_legal_courts : num 3.15 4.33 1.97 2.93 4.2 ...
## $ ef_legal_protection : num 4.51 4.69 2.51 4.26 5.66 ...
## $ ef_legal_military : num 8.33 4.17 3.33 7.5 5.83 ...
## $ ef_legal_integrity : num 4.17 5 4.17 3.33 5 ...
## $ ef_legal_enforcement : num 4.39 4.51 2.3 3.63 5.2 ...
## $ ef_legal_restrictions : num 6.49 6.63 5.46 6.86 9.8 ...
## $ ef_legal_police : num 6.93 6.14 3.02 3.39 5.71 ...
## $ ef_legal_crime : num 6.22 6.74 4.29 4.13 7.01 ...
## $ ef_legal_gender : num 0.949 0.821 0.846 0.769 1 ...
## $ ef_legal : num 5.07 4.69 2.96 3.9 5.81 ...
## $ ef_money_growth : num 8.99 6.96 9.39 5.23 9.08 ...
## $ ef_money_sd : num 9.48 8.34 4.99 5.22 9.26 ...
## $ ef_money_inflation : num 9.74 8.72 3.05 2 9.75 ...
## $ ef_money_currency : num 10 5 5 10 10 10 10 5 0 10 ...
## $ ef_money : num 9.55 7.25 5.61 5.61 9.52 ...
## $ ef_trade_tariffs_revenue : num 9.63 8.48 8.99 6.06 8.87 ...
## $ ef_trade_tariffs_mean : num 9.24 6.22 7.72 7.26 8.76 9.5 8.96 8.2 3.36 9.06 ...
## $ ef_trade_tariffs_sd : num 8.02 5.92 4.25 5.94 8.02 ...
## $ ef_trade_tariffs : num 8.96 6.87 6.99 6.42 8.55 ...
## $ ef_trade_regulatory_nontariff : num 5.57 4.96 3.13 4.47 5.92 ...
## $ ef_trade_regulatory_compliance : num 9.405 0 0.917 5.156 8.466 ...
## $ ef_trade_regulatory : num 7.49 2.48 2.02 4.81 7.19 ...
## $ ef_trade_black : num 10 5.56 10 0 10 ...
## $ ef_trade_movement_foreign : num 6.31 3.66 2.95 5.36 5.11 ...
## $ ef_trade_movement_capital : num 4.615 0 3.077 0.769 5.385 ...
## $ ef_trade_movement_visit : num 8.297 1.106 0.111 7.965 10 ...
## $ ef_trade_movement : num 6.41 1.59 2.04 4.7 6.83 ...
## [list output truncated]
## - attr(*, "spec")=
## .. cols(
## .. X1 = col_double(),
## .. year = col_double(),
## .. ISO_code = col_character(),
## .. countries = col_character(),
## .. region = col_character(),
## .. pf_rol_procedural = col_double(),
## .. pf_rol_civil = col_double(),
## .. pf_rol_criminal = col_double(),
## .. pf_rol = col_double(),
## .. pf_ss_homicide = col_double(),
## .. pf_ss_disappearances_disap = col_double(),
## .. pf_ss_disappearances_violent = col_double(),
## .. pf_ss_disappearances_organized = col_double(),
## .. pf_ss_disappearances_fatalities = col_double(),
## .. pf_ss_disappearances_injuries = col_double(),
## .. pf_ss_disappearances = col_double(),
## .. pf_ss_women_fgm = col_double(),
## .. pf_ss_women_missing = col_double(),
## .. pf_ss_women_inheritance_widows = col_double(),
## .. pf_ss_women_inheritance_daughters = col_double(),
## .. pf_ss_women_inheritance = col_double(),
## .. pf_ss_women = col_double(),
## .. pf_ss = col_double(),
## .. pf_movement_domestic = col_double(),
## .. pf_movement_foreign = col_double(),
## .. pf_movement_women = col_double(),
## .. pf_movement = col_double(),
## .. pf_religion_estop_establish = col_double(),
## .. pf_religion_estop_operate = col_double(),
## .. pf_religion_estop = col_double(),
## .. pf_religion_harassment = col_double(),
## .. pf_religion_restrictions = col_double(),
## .. pf_religion = col_double(),
## .. pf_association_association = col_double(),
## .. pf_association_assembly = col_double(),
## .. pf_association_political_establish = col_double(),
## .. pf_association_political_operate = col_double(),
## .. pf_association_political = col_double(),
## .. pf_association_prof_establish = col_double(),
## .. pf_association_prof_operate = col_double(),
## .. pf_association_prof = col_double(),
## .. pf_association_sport_establish = col_double(),
## .. pf_association_sport_operate = col_double(),
## .. pf_association_sport = col_double(),
## .. pf_association = col_double(),
## .. pf_expression_killed = col_double(),
## .. pf_expression_jailed = col_double(),
## .. pf_expression_influence = col_double(),
## .. pf_expression_control = col_double(),
## .. pf_expression_cable = col_double(),
## .. pf_expression_newspapers = col_double(),
## .. pf_expression_internet = col_double(),
## .. pf_expression = col_double(),
## .. pf_identity_legal = col_double(),
## .. pf_identity_parental_marriage = col_double(),
## .. pf_identity_parental_divorce = col_double(),
## .. pf_identity_parental = col_double(),
## .. pf_identity_sex_male = col_double(),
## .. pf_identity_sex_female = col_double(),
## .. pf_identity_sex = col_double(),
## .. pf_identity_divorce = col_double(),
## .. pf_identity = col_double(),
## .. pf_score = col_double(),
## .. pf_rank = col_double(),
## .. ef_government_consumption = col_double(),
## .. ef_government_transfers = col_double(),
## .. ef_government_enterprises = col_double(),
## .. ef_government_tax_income = col_double(),
## .. ef_government_tax_payroll = col_double(),
## .. ef_government_tax = col_double(),
## .. ef_government = col_double(),
## .. ef_legal_judicial = col_double(),
## .. ef_legal_courts = col_double(),
## .. ef_legal_protection = col_double(),
## .. ef_legal_military = col_double(),
## .. ef_legal_integrity = col_double(),
## .. ef_legal_enforcement = col_double(),
## .. ef_legal_restrictions = col_double(),
## .. ef_legal_police = col_double(),
## .. ef_legal_crime = col_double(),
## .. ef_legal_gender = col_double(),
## .. ef_legal = col_double(),
## .. ef_money_growth = col_double(),
## .. ef_money_sd = col_double(),
## .. ef_money_inflation = col_double(),
## .. ef_money_currency = col_double(),
## .. ef_money = col_double(),
## .. ef_trade_tariffs_revenue = col_double(),
## .. ef_trade_tariffs_mean = col_double(),
## .. ef_trade_tariffs_sd = col_double(),
## .. ef_trade_tariffs = col_double(),
## .. ef_trade_regulatory_nontariff = col_double(),
## .. ef_trade_regulatory_compliance = col_double(),
## .. ef_trade_regulatory = col_double(),
## .. ef_trade_black = col_double(),
## .. ef_trade_movement_foreign = col_double(),
## .. ef_trade_movement_capital = col_double(),
## .. ef_trade_movement_visit = col_double(),
## .. ef_trade_movement = col_double(),
## .. ef_trade = col_double(),
## .. ef_regulation_credit_ownership = col_double(),
## .. ef_regulation_credit_private = col_double(),
## .. ef_regulation_credit_interest = col_double(),
## .. ef_regulation_credit = col_double(),
## .. ef_regulation_labor_minwage = col_double(),
## .. ef_regulation_labor_firing = col_double(),
## .. ef_regulation_labor_bargain = col_double(),
## .. ef_regulation_labor_hours = col_double(),
## .. ef_regulation_labor_dismissal = col_double(),
## .. ef_regulation_labor_conscription = col_double(),
## .. ef_regulation_labor = col_double(),
## .. ef_regulation_business_adm = col_double(),
## .. ef_regulation_business_bureaucracy = col_double(),
## .. ef_regulation_business_start = col_double(),
## .. ef_regulation_business_bribes = col_double(),
## .. ef_regulation_business_licensing = col_double(),
## .. ef_regulation_business_compliance = col_double(),
## .. ef_regulation_business = col_double(),
## .. ef_regulation = col_double(),
## .. ef_score = col_double(),
## .. ef_rank = col_double(),
## .. hf_score = col_double(),
## .. hf_rank = col_double(),
## .. hf_quartile = col_double()
## .. )
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
## corrplot 0.84 loaded
corrplot(cor(hfiwc %>%
select(pf_ss_women_fgm:pf_movement_women)),
method="color",
sig.level = 0.01, insig = "blank",
addCoef.col = "black",
tl.srt=45,
type="upper"
)

score = hfi %>% filter(year == 2016) %>% select(ISO_code, countries, region, pf_score, pf_rank, ef_score, ef_rank, hf_score, hf_rank) %>% na.omit()
p1 =ggplot(score, aes(x = ef_score, y = pf_score, color = region), group = countries)
pointsToLabel <- c("Russia", "Venezuela", "Iraq", "Myanmar", "Sudan",
"Afghanistan", "Congo", "Greece", "Argentina", "Brazil",
"India", "Italy", "China", "South Africa", "Spain",
"Botswana", "Cape Verde", "Bhutan", "Rwanda", "France",
"United States", "Germany", "Britain", "Barbados", "Norway", "Japan",
"New Zealand", "Singapore")
mR2 <- summary(lm(pf_score ~ 1 + ef_score , data = score))$r.squared
mR2 <- paste0(format(mR2, digits = 2), "%")
p2 = p1 + geom_smooth(mapping = aes(linetype = "r2"),
method = "lm",se = FALSE,
color = "red") + # geom_point(size = 2, stroke = 1.25) +
geom_point(aes(size = round(hf_score)), alpha = 0.6)+ labs(size = "Human Freedom Score") +
geom_text_repel(aes(label = countries) , color = "black", size = 2.5, data = filter(score, countries %in% pointsToLabel), force = 2 ) + #check_overlap = TRUE
scale_x_continuous(name = "Economic Freedom Score, 2016 (10 = Most Free)", limits = c(2.5,9.5), breaks = 2.5:9.5) +
scale_y_continuous(name = "Personal Freedom Score, 2016 (10 = Most Free)", limits = c(2.5,9.5), breaks = 2.5:9.5) +
scale_color_brewer(name = "" , type = 'div', palette = 'Spectral') +
scale_linetype(name = "",
breaks = "r2",
labels = list(bquote(R^2==.(mR2))),
guide = guide_legend(override.aes = list(linetype = 1, size = 2, color = "red"), order=2)) +
ggtitle("Economic and Personal Freedom 2016") +
theme_minimal() + # start with a minimal theme and add what we need
theme(text = element_text(color = "gray20"),
legend.text = element_text(size = 10, color = "gray10"),
axis.text = element_text(face = "italic"),
axis.title.x = element_text(vjust = -1), # move title away from axis
axis.title.y = element_text(vjust = 2), # move away for axis
axis.ticks.y = element_blank(), # element_blank() is how we remove elements
axis.line = element_line(color = "gray40", size = 0.3),
#panel.grid.major = element_blank()
#axis.line.y = element_blank()
panel.grid.major = element_line(color = "gray", size = 0.2)
#panel.grid.major.x = element_blank()
)
suppressWarnings(print(p2))

hfi_cc_2018 <- read_csv("hfi_cc_2018.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## .default = col_double(),
## ISO_code = col_character(),
## countries = col_character(),
## region = col_character()
## )
## See spec(...) for full column specifications.
#2008 Personal Freedom vs Economic Freedom
score = hfi_cc_2018 %>% filter(year == 2016) %>% select(ISO_code, countries, region, pf_score, pf_rank, ef_score, ef_rank, hf_score, hf_rank) %>% na.omit()
p1 =ggplot(score, aes(x = ef_score, y = pf_score, color = region), group = countries)
pointsToLabel <- c("Russia", "Venezuela", "Iraq", "Myanmar", "Sudan",
"Afghanistan", "Congo", "Greece", "Argentina", "Brazil",
"India", "Italy", "China", "South Africa", "Spain",
"Botswana", "Cape Verde", "Bhutan", "Rwanda", "France",
"United States", "Germany", "Britain", "Barbados", "Norway", "Japan",
"New Zealand", "Singapore")
mR2 <- summary(lm(pf_score ~ 1 + ef_score , data = score))$r.squared
mR2 <- paste0(format(mR2, digits = 2), "%")
p2 = p1 + geom_smooth(mapping = aes(linetype = "r2"),
method = "lm",se = FALSE,
color = "red") + # geom_point(size = 2, stroke = 1.25) +
geom_point(aes(size = round(hf_score)), alpha = 0.6)+ labs(size = "Human Freedom Score") +
geom_text_repel(aes(label = countries) , color = "black", size = 2.5, data = filter(score, countries %in% pointsToLabel), force = 2 ) + #check_overlap = TRUE
scale_x_continuous(name = "Economic Freedom Score, 2016 (10 = Most Free)", limits = c(2.5,9.5), breaks = 2.5:9.5) +
scale_y_continuous(name = "Personal Freedom Score, 2016 (10 = Most Free)", limits = c(2.5,9.5), breaks = 2.5:9.5) +
scale_color_brewer(name = "" , type = 'div', palette = 'Spectral') +
scale_linetype(name = "",
breaks = "r2",
labels = list(bquote(R^2==.(mR2))),
guide = guide_legend(override.aes = list(linetype = 1, size = 2, color = "red"), order=2)) +
ggtitle("Economic and Personal Freedom 2016") +
theme_minimal() + # start with a minimal theme and add what we need
theme(text = element_text(color = "gray20"),
legend.text = element_text(size = 10, color = "gray10"),
axis.text = element_text(face = "italic"),
axis.title.x = element_text(vjust = -1), # move title away from axis
axis.title.y = element_text(vjust = 2), # move away for axis
axis.ticks.y = element_blank(), # element_blank() is how we remove elements
axis.line = element_line(color = "gray40", size = 0.3),
#panel.grid.major = element_blank()
#axis.line.y = element_blank()
panel.grid.major = element_line(color = "gray", size = 0.2)
#panel.grid.major.x = element_blank()
)
suppressWarnings(print(p2))

#chloropeth map of Human freedom score 2016
# light grey boundaries
l <- list(color = toRGB("grey"), width = 0.5)
# specify map projection/options
g <- list(
showframe = FALSE,
showcoastlines = FALSE,
projection = list(type = 'Mercator')
)
plot_geo(score) %>%
add_trace(
z = ~ round(hf_score, 2), color = ~hf_score, colors = 'Blues',
text = ~countries, locations = ~ISO_code, marker = list(line = l)
) %>%
colorbar(title = 'Human Freedom Score, 2016') %>%
layout(
title = 'Human Freedome Score, 2016',
geo = g
)
#2016 women Personal Freedom vs Economic Freedom
score = hfi_cc_2018 %>% filter(year == 2016) %>% select(ISO_code, countries, region, pf_score, pf_rank, ef_score, ef_rank, hf_score, hf_rank) %>% na.omit()
p1 =ggplot(score, aes(x = ef_score, y = pf_score, color = region), group = countries)
pointsToLabel <- c("Russia", "Venezuela", "Iraq", "Myanmar", "Sudan",
"Afghanistan", "Congo", "Greece", "Argentina", "Brazil",
"India", "Italy", "China", "South Africa", "Spain",
"Botswana", "Cape Verde", "Bhutan", "Rwanda", "France",
"United States", "Germany", "Britain", "Barbados", "Norway", "Japan",
"New Zealand", "Singapore")
mR2 <- summary(lm(pf_score ~ 1 + ef_score , data = score))$r.squared
mR2 <- paste0(format(mR2, digits = 2), "%")
p2 = p1 + geom_smooth(mapping = aes(linetype = "r2"),
method = "lm",se = FALSE,
color = "red") + # geom_point(size = 2, stroke = 1.25) +
geom_point(aes(size = round(hf_score)), alpha = 0.6)+ labs(size = "Human Freedom Score") +
geom_text_repel(aes(label = countries) , color = "black", size = 2.5, data = filter(score, countries %in% pointsToLabel), force = 2 ) + #check_overlap = TRUE
scale_x_continuous(name = "Economic Freedom Score, 2016 (10 = Most Free)", limits = c(2.5,9.5), breaks = 2.5:9.5) +
scale_y_continuous(name = "Personal Freedom Score, 2016 (10 = Most Free)", limits = c(2.5,9.5), breaks = 2.5:9.5) +
scale_color_brewer(name = "" , type = 'div', palette = 'Spectral') +
scale_linetype(name = "",
breaks = "r2",
labels = list(bquote(R^2==.(mR2))),
guide = guide_legend(override.aes = list(linetype = 1, size = 2, color = "red"), order=2)) +
ggtitle("Economic and Personal Freedom 2016") +
theme_minimal() + # start with a minimal theme and add what we need
theme(text = element_text(color = "gray20"),
legend.text = element_text(size = 10, color = "gray10"),
axis.text = element_text(face = "italic"),
axis.title.x = element_text(vjust = -1), # move title away from axis
axis.title.y = element_text(vjust = 2), # move away for axis
axis.ticks.y = element_blank(), # element_blank() is how we remove elements
axis.line = element_line(color = "gray40", size = 0.3),
#panel.grid.major = element_blank()
#axis.line.y = element_blank()
panel.grid.major = element_line(color = "gray", size = 0.2)
#panel.grid.major.x = element_blank()
)
suppressWarnings(print(p2))

#2008 personal freedom
df = hfi_cc_2018 %>% filter(year == 2008) %>% select(year, ISO_code, countries, region, starts_with('pf_'))
df=df[,colSums(is.na(df))<nrow(df)]
df = df %>% na.omit()
cormat <- round(cor(df[,5:57]),2)
#
get_lower_tri<-function(cormat){
cormat[upper.tri(cormat)] <- NA
return(cormat)
}
get_upper_tri <- function(cormat){
cormat[lower.tri(cormat)]<- NA
return(cormat)
}
#
reorder_cormat <- function(cormat){
# Use correlation between variables as distance
dd <- as.dist((1-cormat)/2) #what does this do?
hc <- hclust(dd)
cormat <-cormat[hc$order, hc$order]
}
# Reorder the correlation matrix
cormat <- reorder_cormat(cormat)
upper_tri <- get_upper_tri(cormat)
# Melt the correlation matrix
melted_cormat <- melt(upper_tri, na.rm = TRUE)
# Create a ggheatmap
ggheatmap <- ggplot(melted_cormat, aes(Var2, Var1, fill = value))+
geom_tile(color = "white")+
scale_fill_gradient2(low = "blue", high = "red", mid = "white",
midpoint = 0, limit = c(-1,1), space = "Lab",
name="Pearson\nCorrelation") +
theme_minimal()+ # minimal theme
theme(axis.text.x = element_text(angle = 45, vjust = 1,
size = 8.5, hjust = 1),
panel.grid.major = element_line(color = "gray", size = 0.2)) +
coord_fixed()
ggheatmap +
#geom_text(aes(Var2, Var1, label = value), color = "black", size = 2.5) +
theme(
#axis.line = element_line(color = "gray40", size = 0.3),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_line(color = "gray", size = 0.2),
#panel.grid.major.x = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.ticks = element_blank()
) + ggtitle("Personal Freedom, 2008")
